package cn.tth.test.game.bean;

import cn.tth.test.game.annotations.Bean;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.InvocationTargetException;

@Data
public class BeanDefinition {

    private String beanName;

    private String beanClassName;

    private Class<?> beanClass;

    private Object bean;

    private String definitionName;

    public BeanDefinition(Class<?> beanClass,String beanName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        this.beanClass = beanClass;
        this.bean = beanClass.getDeclaredConstructor().newInstance();
        this.beanClassName = beanClass.getName();
        this.beanName = beanName;
        Bean beanClassDeclaredAnnotation = beanClass.getDeclaredAnnotation(Bean.class);
        String value = beanClassDeclaredAnnotation.value();
        if(StringUtils.isBlank(value)){
            this.definitionName = beanName;
        }else {
            this.definitionName = value;
        }
    }
}
